<?php
use Illuminate\Database\Eloquent\SoftDeletingTrait;

class PurchaseOrder extends Eloquent {
	
	use SoftDeletingTrait;
	
	protected $dates = ['deleted_at'];
		
	protected $table = 'purchase_order';

	/**
	 * Condition: Unarchived Items.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @param $query
	 * @return mixed
	 */
	public function scopeActive( $query ) {
		return $query->where($this->table . '.archived', 0);
	}

	/**
	 * Retrieves Order Products under Purchase Order.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function purchaseOrderProducts() {
		// Model, Related Key, Foreign Key
		return $this->hasMany('PurchaseOrderProduct', 'PURCHASE_ORDER_id', 'id');
	}
	
	/**
	 * Relates to Vendor.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function vendor() {
		return $this->belongsTo('Vendor', 'VENDOR_id');
	}
	
	/**
	 * Relates to User Creator.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function createdBy() {
		return $this->belongsTo('User', 'created_by');
	}
	
	/**
	 * Relates to User Modifier.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function modifiedBy() {
		return $this->belongsTo('User', 'modified_by');
	}

	/**
	 * Relates to User Approver.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function approvedBy() {
		return $this->belongsTo('User', 'approved_by');
	}
	
	/**
	 * Relates to Company.
	 * @author AngelaMisa 03/12/2015 2:30PM
	 * @return mixed
	 */
	public function company() {
		return $this->belongsTo('Company', 'company_code', 'code');
	}
}